import java.util.Stack;

public class SortedStack {

    private Stack<Integer> stack;
    public SortedStack() {
        stack = new Stack<>();
    }

    public void push(int val) {
        Stack<Integer> temp = new Stack<>();
        while (!stack.isEmpty() && stack.peek() < val) {
            temp.push(stack.pop());
        }
        stack.push(val);
        while (!temp.isEmpty()) {
            stack.push(temp.pop());
        }
    }

    public void pop() {
        if (!isEmpty()) stack.pop();
    }

    public int peek() {
        if (!isEmpty()) return stack.peek();
        return -1;
    }

    public boolean isEmpty() {
        return stack.isEmpty();
    }
}
